<?php
/**
 * Celebrio 
 * 
 * @copyright  Copyright (c) 2011 Celebrio Software
 * @package    Celebrio
 */
namespace Celebrio;

use Nette\Environment;

use Celebrio\PasswordGenerator;

/**
 * Class to hash passwords
 *
 * @author     Albireo Solutions
 * @package    Kernel
 */
final class PasswordHasher {
    
    /**
     * Generates and returns the database password for the user identified by $username.
     *
     * @param String $username
     * @param String $pass the user password
     * @return String the database machine password
     */
    public static function databaseHash($username, $hashedPassword) {
        Environment::loadConfig(Environment::expand("%appDir%").'/shadow.ini');
        $dbSalt = Environment::getConfig('password')->dbSalt;
        $password = hash('sha1',$dbSalt.$hashedPassword.(PasswordGenerator::generatePass($username)));
        return "*".$password;
    }

    public static function userHash($username, $password) {
        Environment::loadConfig(Environment::expand("%appDir%").'/shadow.ini');
        $userSalt = Environment::getConfig('password')->userSalt;
        $password = hash('sha512', PasswordGenerator::generatePass($username).$password.$userSalt);
        return $password;
    }
}
